package com.example.graphicslib.animations;

import android.graphics.Matrix;

import com.example.graphicslib.utils.RotationDirection;

/**
 * Created by Tatev on 23/3/2014.
 */
public class BaseRotationAnimation implements Rotatable {

    //TODO


    public BaseRotationAnimation(int rotationCount, RotationDirection direction, float width, float height, long duration) {
        this.deltaAngle = 360f / rotationCount;
        this.direction = direction;
        this.width = width;
        this.height = height;
        this.duration = duration;
    }


    @Override
    public void setRotationCount(int rotationCount) {
        this.deltaAngle = 360f / rotationCount;
    }

    @Override

    public void setRotationDirection(RotationDirection direction) {
        this.direction = direction;
    }

    public void setCoordinates(float x, float y){
        this.x = x;
        this.y = y;
    }


    @Override
    public void onTickResponse(long elapsedTime) {

        matrix = new Matrix();
        matrix.preRotate((direction == RotationDirection.CLOCKWISE)? currentAngle: -currentAngle, width / 2, height / 2);
        matrix.postTranslate(x, y);
        currentAngle += deltaAngle;
        currentAngle %= 360;
    }

    @Override
    public void onFinishResponse() {

    }

    @Override
    public long getDuration() {
        return duration;
    }

    public Matrix getRotationMatrix(){
        return matrix;
    }

    private long duration;
    private float deltaAngle;
    private float currentAngle;
    private float x, y;
    private float width, height;
    private RotationDirection direction;
    private Matrix matrix;
}
